package gui.panels;

import gui.tools.ActionHandler;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextArea;

import mysql.CustomQueries;

public class CustomPanel extends JPanel implements ActionListener {
	
	public CustomQueries cusQueries;
	public JTable display;
	public JTextArea input;
	public JButton commit;
	
	
	public CustomPanel(ActionHandler ac) {
		commit = new JButton("Commit");
		commit.addActionListener(this);		
		input = new JTextArea();
		input.setLineWrap(true);
		display = new JTable();
		setLayout(new GridLayout(3,1,4,4));
		
		add(input);
		add(display);
		add(commit);
	}
	
	public void getData() {
		this.remove(display);
		this.remove(commit);
		cusQueries = new CustomQueries();
		display = cusQueries.getTable(input.getText());
		this.add(display);
		this.add(commit);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == this.commit) {
			getData();
			this.repaint();
			this.validate();
		}
	}
}
